#历史
from selenium.webdriver.common.by import By
from base.base import Base


class PageHistory(Base):
    pagetitle_locator = (By.XPATH,'(//li[@role="menuitem"])[4]')
    #站点查询框
    input_site_locator = (By.CLASS_NAME,'ant-select-selection-search-input')
    #下拉框第一个元素
    seleted_locator = (By.XPATH,'(//div[@class="ant-cascader-menus"]//li)[1]')
    #设备查询框
    input_deivce_locator = (By.XPATH,'//input[@class="ant-input"]')
    #设备选择
    devices_locator = (By.CLASS_NAME,'custom-tree-node')
    #设备名称
    device_headtitle_locator = (By.CLASS_NAME,'ant-card-body')
    #历史数据
    historydata_locator = (By.XPATH,'//tbody[@class="ant-table-tbody"]//td')
    def page_jump(self):
        self.click(self.pagetitle_locator)
    #站点选择
    def input_site(self,name):
        self.clear(self.input_site_locator)
        self.input(self.input_site_locator,name)
        self.click(self.seleted_locator)
    def input_device(self,name):
        self.clear(self.input_deivce_locator)
        self.input(self.input_deivce_locator,name)
        self.click(self.devices_locator)
    #获取设备名
    def get_headtitle(self):
        return self.finds(self.device_headtitle_locator)[1].text
    #获取历史数据
    def get_historydata(self):
        values = []
        elms = self.presences(self.historydata_locator)
        for elm in elms:
            if elm.text != '':
                values.append(elm.text)
        return sorted(values)
            
